<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col>
      <strong v-if="isRoot">
        <i class="el-icon-office-building" /> {{ nodeData.name }}</strong>
      <span v-else>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartment">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="editDepartment">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delDepartment">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
// 添加部门功能2 添加点击事件，并且告诉父组件
import { delDepartment } from '@/api/department'
export default {
  components: {},
  //   1 父传子  在props里面  2  定义数据，起个名字
  //  3 定义类型 必
  //   4 页面渲染，用这边定义的名字
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {}
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async delDepartment() {
      // console.log('点击了删除部门')
      await this.$confirm('确定删除吗')
      // 调用接口
      await delDepartment(this.nodeData.id)
      // 提示用户
      this.$message.success('删除部门成功')
      // 更新页面--通知父组件，子传父
      this.$emit('delDepartment')
    },
    addDepartment() {
      // 不让页面数据重复  1
      // 告诉父亲的时候把数据带过去
      this.$emit('addDepartment', this.nodeData)
    },
    editDepartment() {
      this.$emit('editDepartment', this.nodeData)
    }
  }
}
</script>

<style scoped lang="less">
</style>
